// index.js
Page({
  data:{
    jxwLeft:280,
    state:0,
    inertia:true,
    venueData:[
      {"venTitle":"标题1","venTime":"00:00-24:00"},
      {"venTitle":"标题2","venTime":"00:00-24:00"},
      {"venTitle":"测试测试","venTime":"00:00-24:00"},
      {"venTitle":"哈哈哈","venTime":"00:00-24:00"}
    ]
  },
  onReady:function(){
    console.log("页面加载完成了")
    //定时任务 -- 定时移动
    setInterval(()=>{
      let x =  this.data.jxwLeft += this.data.state;
      console.log("x",x);
      console.log("this.data.jxwLeft",this.data.jxwLeft);
      console.log("this.data.state",this.data.state);
      console.log("this.data.inertia",this.data.inertia);
      this.setData({
        jxwLeft:x
      })
    },10);

    //开启
    wx.startGyroscope({
      interval:"game",
      success:()=>{
        console.log("陀螺仪开启成功");
      }
    })
    //获取监听参数
    wx.onGyroscopeChange((result) => {
      if(result.x >= 0.02 && this.data.inertia){
        this.setData({state:1,inertia:false});
        //惯性刹车
        setTimeout(()=>{
          this.setData({inertia:true});
        },1000);
      }else if(result.x <= -0.02 && this.data.inertia){
        this.setData({state:-1,inertia:false});
        //惯性刹车
        setTimeout(()=>{
          this.setData({inertia:true});
        },1000);
      }else if(this.data.inertia){
        this.setData({state:0});
      }
      //console.log(result);
    })

  },
  contactUs(){
    //wx.vibrateLong();
    wx.createRewardedVideoAd({
      adUnitId: '123456',
    })
  }
})
